"""
图标生成器 - 为系统托盘创建简单图标
"""

from PIL import Image, ImageDraw

def create_monitor_icon(size=64, color="#007acc", bg_color=(0, 0, 0, 0)):
    """
    创建一个简单的监控图标
    
    参数:
        size: 图标大小，默认64x64像素
        color: 图标颜色，默认蓝色
        bg_color: 背景颜色，默认透明
        
    返回:
        PIL.Image: 创建的图标图像
    """
    # 创建透明背景图像
    image = Image.new("RGBA", (size, size), bg_color)
    draw = ImageDraw.Draw(image)
    
    # 计算一些基本尺寸
    border = int(size * 0.12)
    inner_size = size - 2 * border
    
    # 绘制一个计算机显示器形状
    # 显示器主体
    monitor_width = inner_size
    monitor_height = int(inner_size * 0.7)
    draw.rectangle(
        (border, border, border + monitor_width, border + monitor_height),
        outline=color,
        width=max(int(size * 0.06), 1)
    )
    
    # 显示器底座
    base_width = int(monitor_width * 0.4)
    base_height = int(monitor_height * 0.2)
    base_left = border + (monitor_width - base_width) // 2
    base_top = border + monitor_height
    draw.rectangle(
        (base_left, base_top, base_left + base_width, base_top + base_height),
        outline=color,
        width=max(int(size * 0.06), 1)
    )
    
    # 绘制一些曲线线条表示性能监控
    line_start_x = border + int(monitor_width * 0.2)
    line_end_x = border + int(monitor_width * 0.8)
    line_y1 = border + int(monitor_height * 0.3)
    line_y2 = border + int(monitor_height * 0.5)
    line_y3 = border + int(monitor_height * 0.7)
    
    # 绘制三条波动线
    points1 = [
        (line_start_x, line_y1), 
        (line_start_x + int(monitor_width * 0.2), line_y1 - int(size * 0.1)),
        (line_start_x + int(monitor_width * 0.4), line_y1 + int(size * 0.05)),
        (line_end_x, line_y1 - int(size * 0.05))
    ]
    draw.line(points1, fill=color, width=max(int(size * 0.03), 1))
    
    points2 = [
        (line_start_x, line_y2), 
        (line_start_x + int(monitor_width * 0.3), line_y2 + int(size * 0.08)),
        (line_end_x, line_y2 - int(size * 0.08))
    ]
    draw.line(points2, fill=color, width=max(int(size * 0.03), 1))
    
    points3 = [
        (line_start_x, line_y3), 
        (line_start_x + int(monitor_width * 0.5), line_y3 - int(size * 0.06)),
        (line_end_x, line_y3 + int(size * 0.02))
    ]
    draw.line(points3, fill=color, width=max(int(size * 0.03), 1))
    
    return image

def save_icon(file_path="monitor_icon.png", size=64):
    """保存图标到文件"""
    icon = create_monitor_icon(size)
    icon.save(file_path)
    return file_path

if __name__ == "__main__":
    # 生成并保存图标
    icon_path = save_icon()
    print(f"图标已保存到: {icon_path}")
    
    # 显示图标（如果在有GUI的环境中）
    try:
        icon = create_monitor_icon(128)  # 创建大一点的图标便于查看
        icon.show()
    except Exception as e:
        print(f"无法显示图标: {e}") 